package com.qys.training.listen;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

import javax.annotation.Resource;

public class CloseListener implements ApplicationListener<ContextClosedEvent> {
    private final Logger logger = LoggerFactory.getLogger(CloseListener.class);

    @Resource
    private HazelcastInstance hazelcastinstance;

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        IMap<Object, Object> map = hazelcastinstance.getMap("listener");
        map.put("listener", 0);
        logger.info("openapi项目关闭");
    }
}
